No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
-------
Modules are one of the most useful yet least understood aspects of MicroPhone. With them you can add new functionality to a number of settings documents, without importing dozens of scripts into those documents. You can create a single module that does a number of things, and make it available to all of your settings documents, simply by including one-line in your settings document's turnkey opening action:
Module * Load "'MyModule'"
You can also create a one-line script with the above line and run it from within your settings document. From that moment on, all of the scripts in the module will be available to your settings document. If a script of the same name exists in both the module and your settings document, the version in the module will take the place of the one in your settings document.
Creating a Module
To create a module, bring up the Script Manager by choosing Edit Scripts from the Scripts menu. Choose Module from the Script Type popup menu. Then, choose New Module from the File menu. A new module called "untitled" is created. Now, you can create new scripts, or import existing ones.
When you are finished working on the scripts in your new module, choose Save Module from the File menu. The file dialog defaults to the Module Folder, if one exists. Otherwise, it defaults to the location of the MicroPhone application. Give your module a name and click the Save button.
Note: the Menu and Button checkboxes in the Script Editor for module scripts will do nothing if checked. Module scripts cannot appear on the Scripts menu, nor can they automatically appear as buttons on the button bar. However, module scripts may be installed on the button bar with the Install Button script command.
Editing a Module
To edit a module, bring up the Script Manager by chooing Edit Scripts from the Scripts menu. Choose Module from the Script Type popup menu. Then, choose Open Module… from the File menu. The file dialog defaults to the Module Folder, if one exists. Otherwise, it defaults to the location of the MicroPhone application. Find your module and click the Open button. The scripts for your module will appear in the scripts list.
Make your changes. When you are finished working on the scripts in the module, chose Save Module from the File menu.
Using a Module
To use a script in a module, write a script in your settings document that contains the following lines:
Module * Load "'Utilities'"
Do Script * "'theDate'"
where Utilities is the name of your module and theDate is the name of the script in the module. If the Utilities module is in the Module Folder, you need only specify the name of the module. Otherwise, you will need to specify the full path of the module. For example, if you keep your "Utilities" module in a folder called "Special", located at the root of your Hard Disk named "SuperDrive", you would use the following script lines:
Module * Load "'SuperDrive:Special:Utilities'"
Do Script * "'theDate'"
Also, you can run a module script in one step:
Do Script * "'theDate','Utilities'"
or
Do Script * "'theDate','SuperDrive:Special:Utilities'"
This method of using the Do Script command automatically loads the module and runs the script. After the script is finished, the module remains loaded. To unload the module, use the command:
Module * Unload "'Utilities'"
or
Module * Unload "'SuperDrive:Special:Utilities'"
Examples
We've included several examples of module scripts that might be useful in many different settings documents. They are simple scripts, but show you what is possible by using modules. The module is called Utilities, which contains three scripts, theDate, theFile, and theFolder. These scripts are installed on the button bar of the settings document when you click the "Load" button.